home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / KEYSET.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  7KB  |  238 lines

  1. ;================================================================
  2. ; KEYSET By Eric Tauck
  3. ;
  4. ; This program sets the caps lock, num lock, and scroll lock
  5. ; state.  The usage is: 
  6. ;   KEYSET [CAPS ON | OFF] [NUM ON | OFF] [SCROLL ON | OFF] 
  7. ; Example: 
  8. ;   KEYSET CAPS ON SCROLL OFF
  9. ; This turns the caps lock on and the scroll lock off.
  10. ;
  11. ; If you have keyboard LED's, they will only be updated if you are 
  12. ; using an AT class computer.  The keyboard codes as returned by 
  13. ; the BIOS will reflect the state changes regardless of the type 
  14. ; of computer being used. 
  15. ;
  16. ; This program makes use of the WASM library files.
  17.  
  18.         INCLUDE 'library\string.asm'
  19.         INCLUDE 'library\case1.asm'
  20.         INCLUDE 'library\case2.asm'
  21.         INCLUDE 'library\parms.asm'
  22.         INCLUDE 'library\message1.asm'
  23.  
  24. ;--- state change flags
  25.  
  26. C_SET   EQU     0000000000000001B       ;set caps lock
  27. N_SET   EQU     0000000000000010B       ;set num lock
  28. S_SET   EQU     0000000000000100B       ;set scroll lock
  29.  
  30. ;--- BIOS data area constants
  31.  
  32. C_BIT   EQU     01000000B       ;caps lock bit
  33. N_BIT   EQU     00100000B       ;num lock bit
  34. S_BIT   EQU     00010000B       ;scroll lock bit
  35.  
  36. BDATA_SEG       EQU     0040H   ;segment of target data area
  37. BDATA_OFF       EQU     0017H   ;offset of target data area
  38.  
  39. ;--- program entry
  40.  
  41.         mov     ax, OFFSET banner       ;banner address
  42.         call    MesPutL                 ;display
  43.  
  44.         sub     ah, ah          ;zero bits
  45.         sub     di, di          ;clear all flags
  46.         jmps    main2           ;enter loop
  47.  
  48. main1   mov     al, C_BIT               ;hardware bit
  49.         mov     bx, OFFSET clock        ;option string
  50.         mov     cx, C_SET               ;flag bit
  51.         call    checkopt                ;check if option
  52.         jc      main2                   ;jump if so
  53.  
  54.         mov     al, N_BIT               ;hardware bit
  55.         mov     bx, OFFSET nlock        ;option string
  56.         mov     cx, N_SET               ;flag bit
  57.         call    checkopt                ;check if option
  58.         jc      main2                   ;jump if so
  59.  
  60.         mov     al, S_BIT               ;hardware bit
  61.         mov     bx, OFFSET slock        ;option string
  62.         mov     cx, S_SET               ;flag bit
  63.         call    checkopt                ;check if option
  64.         jc      main2                   ;jump if so
  65.         jmp     error
  66.  
  67. main2   push    ax
  68.         call    ParGet          ;get next parameter
  69.         mov     si, ax
  70.         pop     ax
  71.         jnc     main1           ;loop back if availible
  72.  
  73.         or      di, di          ;check if any options
  74.         jz      help            ;jump if none
  75.  
  76. ;--- perform all settings, flags in DI and AH
  77.  
  78.         push    ds
  79.         mov     dx, BDATA_SEG   ;
  80.         mov     ds, dx          ;-- load address
  81.         mov     bx, BDATA_OFF   ;
  82.         mov     al, [bx]        ;load keyboard control byte
  83.  
  84. ;--- set caps lock
  85.  
  86.         test    di, C_SET       ;check if set caps lock
  87.         jz      main3
  88.         and     al, NOT C_BIT   ;zero bit
  89.         mov     dl, ah          ;load bit settings
  90.         and     dl, C_BIT       ;mask bit
  91.         or      al, dl          ;set bit on or off
  92.  
  93. ;--- set num lock
  94.  
  95. main3   test    di, N_SET       ;check if set num lock
  96.         jz      main4
  97.         and     al, NOT N_BIT   ;zero bit
  98.         mov     dl, ah          ;load bit settings
  99.         and     dl, N_BIT       ;mask bit
  100.         or      al, dl          ;set bit on or off
  101.  
  102. ;--- set scroll lock
  103.  
  104. main4   test    di, S_SET       ;check if set scroll lock
  105.         jz      main5
  106.         and     al, NOT S_BIT   ;zero bit
  107.         mov     dl, ah          ;load bit settings
  108.         and     dl, S_BIT       ;mask bit
  109.         or      al, dl          ;set bit on or off
  110.  
  111. ;--- finished
  112.  
  113. main5   mov     [bx], al
  114.         pop     ds
  115.  
  116.         mov     ax, 4C00H       ;exit function error code 0
  117.         int     21H             ;execute
  118.  
  119. ;--- no options, display help
  120.  
  121. help    mov     ax, OFFSET helpmes
  122.         call    MesPutL
  123.         mov     ax, 4CFFH
  124.         int     21H
  125.  
  126. ;--- invalid options, display error message
  127.  
  128. error   mov     ax, OFFSET errmes
  129.         call    MesPutL
  130.         mov     ax, 4CFFH
  131.         int     21H
  132.  
  133. ;========================================
  134. ; Try to match an option.
  135. ;
  136. ; In: SI= parameter string; BX= target
  137. ;     string; CX= flag bit; DI= current
  138. ;     flag bits; AH= current hardware
  139. ;     bits; AL= hardware bit.
  140. ;
  141. ; Out: DI & AH updated; CY= set if
  142. ;      option matched; SI= preserved.
  143.  
  144. checkopt PROC   NEAR
  145.         push    ax
  146.         push    cx
  147.         push    di
  148.  
  149.         push    bx
  150.         mov     ax, si
  151.         call    StrUpr          ;convert to uppercase
  152.         pop     bx
  153.         mov     ax, si
  154.         call    StrCmp          ;compare with target string
  155.         jc      chkopt2         ;jump if no match
  156.  
  157.         call    ParGet          ;get ON/OFF
  158.         jc      chkopt3         ;jump if error
  159.         mov     di, ax
  160.         call    StrUpr          ;convert to uppercase
  161.         mov     ax, di
  162.         mov     bx, OFFSET on_str
  163.         call    StrCmp                  ;check if ON
  164.         jnc     chkopt1                 ;jump if so
  165.         mov     ax, di
  166.         mov     bx, OFFSET off_str
  167.         call    StrCmp                  ;check if OFF
  168.         jc      chkopt3                 ;jump if not
  169.  
  170. ;--- found OFF
  171.  
  172.         call    dispopt         ;display
  173.         pop     di
  174.         pop     cx
  175.         pop     ax
  176.         or      di, cx          ;set flag bit
  177.         not     al              ;flip bits
  178.         and     ah, al          ;zero hardware bit
  179.         stc
  180.         ret
  181.  
  182. ;--- found ON
  183.  
  184. chkopt1 call    dispopt         ;display
  185.         pop     di
  186.         pop     cx
  187.         pop     ax
  188.         or      di, cx          ;set flag bit
  189.         or      ah, al          ;set hardware bit
  190.         stc
  191.         ret
  192.  
  193. ;--- string doesn't match
  194.  
  195. chkopt2 pop     di
  196.         pop     cx
  197.         pop     ax
  198.         clc
  199.         ret
  200.  
  201. ;--- error, no ON or OFF
  202.  
  203. chkopt3 jmp     error
  204.         ENDP
  205.  
  206. ;========================================
  207. ; Display the new state.
  208.  
  209. dispopt PROC    NEAR
  210.         mov     ax, si
  211.         call    MesPut
  212.         mov     ax, OFFSET ismes
  213.         call    MesPut
  214.         mov     ax, di
  215.         call    MesPutL
  216.         ret
  217.         ENDP
  218.  
  219. ;========================================
  220. ; Data.
  221.  
  222. clock   DB      'CAPS',0
  223. nlock   DB      'NUM',0
  224. slock   DB      'SCROLL',0
  225.  
  226. on_str  DB      'ON',0
  227. off_str DB      'OFF',0
  228.  
  229. banner  DB      13,10,'KeySet By Eric Tauck',0
  230. helpmes DB      'Usage: KEYSET [CAPS ON | OFF] [NUM ON | OFF]'
  231.         DB      ' [SCROLL ON | OFF]',0
  232. errmes  DB      'Error: run KEYSET without options for help',0
  233. ismes   DB      ' is ',0
  234.